package com.example.homework.homework05;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test {
    public static void main(String[] args) {
        // 1.定义Java基础班的HashMap<String, String>
        HashMap<String, String> JavaSEMap = new HashMap<>();

        // 2.存放2个学生到Java基础班的Map
        JavaSEMap.put("001", "李晨");
        JavaSEMap.put("002", "范冰冰");

        // 3.定义Java就业班的HashMap<String, String>
        HashMap<String, String> JavaEEMap = new HashMap<>();

        // 4.存放2个学生到Java就业班的Map
        JavaEEMap.put("001", "马云");
        JavaEEMap.put("002", "马化腾");

        // 5.定义一个学校集合
        Map<String, HashMap<String, String>> schoolMap = new HashMap<>();
        schoolMap.put("Java基础班", JavaSEMap);
        schoolMap.put("Java就业班", JavaEEMap);

        // 遍历学校集合
        // 遍历方式1
        Set<Map.Entry<String, HashMap<String, String>>> entries = schoolMap.entrySet();
        /*for (Map.Entry<String, HashMap<String, String>> entry : entries) {
            System.out.println(entry.getKey());
            Set<Map.Entry<String, String>> entries1 = entry.getValue().entrySet();
            for (Map.Entry<String, String> stringStringEntry : entries1) {
                System.out.println("\t" + stringStringEntry.getKey() + "\t" + stringStringEntry.getValue());
            }
        }*/


//        for (Map.Entry<String, HashMap<String, String>> entry : entries) {
//            System.out.println(entry.getKey());
//            entry.getValue().forEach((k, v) -> System.out.println("\t" + k + "\t" + v));
//        }

        // 使用Lambda简化
//        entries.forEach(entry -> {
//            System.out.println(entry.getKey());
//            entry.getValue().forEach((k, v) -> System.out.println("\t" + k + "\t" + v));
//        });

        //直接使用Lambda遍历schoolMap
        // 遍历schoolMap 的键是String 可以直接输出 值是一个map集合 所以需要在遍历第二遍
        schoolMap.forEach((k, v) -> {
            System.out.println(k);
            v.forEach((k1, v1) -> System.out.println("\t" + k1 + "\t" + v1));
        });

    }
}
